#include "draw3d_test.h"
#include <QtWidgets/QApplication>
#include <QFile>
#include "map3d.h"

#ifdef _DEBUG
#pragma comment(lib,"Algorithmd.lib")
#else
#pragma comment(lib,"Algorithm.lib")
#endif



QVector<Polygon2d> read_map(QString path) {
    QVector<Polygon2d> polygons;
    QFile file(path);
    if (!file.open(QFile::ReadOnly)) {
        return polygons;
    }

    auto convert = [](QString str) {
        Polygon2d polygon;
        auto subs = str.split(" ");
        if (subs.empty()) {
            return polygon;
        }
        subs.pop_front();
        if (subs.size() % 2 != 0) {
            subs.pop_back();
        }
        for (int i = 0; i < subs.size(); i += 2) {
            double lat = subs[i].toDouble();
            double lon = subs[i + 1].toDouble();
            polygon.push_back(Point2d(lat, lon));
        }
        return polygon;
    };

    while (!file.atEnd()) {
        auto line = file.readLine();
        auto p = convert(line);
        if (p.size() > 0) {
            polygons.push_back(p);
        }
    }
    file.close();
    return polygons;

}

using namespace std;
int main(int argc, char* argv[]) {
    QApplication a(argc, argv);


#if 1

    QVector<Polygon2d> pls =  read_map("map.txt");
    Map3d mw;
    mw.set_map_info(pls);
    mw.show();
#else
    draw3d_test w;
    w.show();
#endif
    return a.exec();
}
